﻿using MCP.Data.CF_Entities;

namespace MCP.Model.Helpers
{
	public static class EntityHelper
	{
		//private static MCPEntities db { get; set; }

		//static EntityHelper()
		//{
		//	db = new MCPEntities();
		//}

		//public static class ShopHelper
		//{
		//	public static Shop GetShopByName(string shopName)
		//	{
		//		return db.Shops.FirstOrDefault(s => s.Name == shopName);
		//	}
		//}

		//public static class CheckHelper
		//{
		//	public static void AddCheck(Check check)
		//	{
		//		db.Checks.AddObject(check);
		//		db.SaveChanges();
		//	}

		//	public static List<Check> GetChecks(string username)
		//	{

		//		var checks = db.Checks.Where(c => c.User.Login == username).ToList();

		//		return checks;
		//	}
		//}

		//public static class UserHelper
		//{
		//	public static Guid GetUserGuidByUsername(string username)
		//	{
		//		return db.Users.FirstOrDefault(u => u.Login == username).ID;
		//	}
		//}

		public static class CategoryHelper
		{
			//public static List<ProductCategory> GetCategories(Guid userID)
			//{
			//    var categories = db.Users.SingleOrDefault(u => u.ID == userID).ProductCategories.ToList();
			//    return categories;
			//}

			//public static void AddCategory(ProductCategory category)
			//{
			//    db.ProductCategories.AddObject(category);
			//    db.SaveChanges();
			//}

			//public static ProductCategory GetCategory(Guid categoryID)
			//{
			//    if (categoryID == Guid.Empty)
			//    {
			//        return null;
			//    }

			//    return db.ProductCategories.SingleOrDefault(c => c.ID == categoryID);
			//}

			//public static ProductCategory GetCategory(string categoryName)
			//{
			//    ProductCategory category = null;
			//    if (!string.IsNullOrEmpty(categoryName))
			//    {
			//        category = db.ProductCategories.SingleOrDefault(c => c.CategoryName == categoryName);
			//    }

			//    return category;
			//}
		}

		public static class SettingsHelper
		{
			//public static double? GetMonthIncome()
			//{
			//	var settings = db.Settings.SingleOrDefault(s => s.UserID == CurrentUserHelper.UserID);
			//	return settings == null
			//			   ? null
			//			   : settings.MonthIncome;
			//}

			//public static double? GetCurrentBalance()
			//{
			//	double? currentBalance = null;

			//	double? monthIncome = GetMonthIncome();
			//	if (monthIncome != null)
			//	{
			//		var moneySpent = db.Checks.Where(c => c.UserID == CurrentUserHelper.UserID).Sum(c => c.TotalPrice);
			//		currentBalance = monthIncome.Value - (double)moneySpent;
			//	}

			//	return currentBalance;
			//}

			//public static double? GetCurrentBalancePercent()
			//{
			//	double? currentBalancePercent = null;
			//	double? currentBalance = null;
			//	double? monthIncome = GetMonthIncome();

			//	if (monthIncome.HasValue)
			//	{
			//		var moneySpent = db.Checks.Where(c => c.UserID == CurrentUserHelper.UserID).Sum(c => c.TotalPrice);
			//		currentBalance = monthIncome.Value - (double)moneySpent;
			//		currentBalancePercent = currentBalance / monthIncome * 100;
			//	}

			//	return currentBalancePercent;
			//}

			//public static double? GetBalanceLeft()
			//{
			//	double? balanceLeft = null;
			//	double? currentBalance = GetCurrentBalance();
			//	double? minBalance = db.Settings.SingleOrDefault(s => s.UserID == CurrentUserHelper.UserID).MinBalance;
			//	if (currentBalance.HasValue)
			//	{
			//		balanceLeft = currentBalance - minBalance;
			//	}

			//	return balanceLeft;
			//}
		}
	}
}